'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-06-07 11:08:26
'''
class BrowserHistory:

    def __init__(self, homepage: str):
        self.visited = [homepage]
        self.farward_list = []


    def visit(self, url: str) -> None:
        self.visited.append(url)
        self.forward_list = []


    def back(self, steps: int) -> str:
        re = ''
        if steps >= len(self.visited):
            self.forward_list = self.visited[1:] + self.forward_list
            re = self.visited[0]
            self.visited = [self.visited[0]]
        else:
            self.forward_list = self.visited[-1*steps:] + self.forward_list
            re = self.visited[-1*steps-1]
            self.visited = self.visited[:-1*steps]
        return re


    def forward(self, steps: int) -> str:
        re = ''
        if steps > len(self.forward_list):
            self.visited = self.visited + self.forward_list
            re = self.visited[-1]
            self.forward_list = []
        else:
            re = self.forward_list[steps-1]
            self.visited = self.visited + self.forward_list[:steps-1]
            self.forward_list = self.forward_list[steps:]
        return re


if __name__ == "__main__":
    # browser = BrowserHistory('leetcode')
    # browser.visit('google')
    # browser.visit('facebook')
    # browser.visit('youtube')
    # print(browser.back(1))
    # print(browser.back(1))
    # print(browser.forward(1))
    # browser.visit('linked')
    # print(browser.forward(2))
    # print(browser.visited)
    # print(browser.back(2))
    # print(browser.back(7))

    # a=[null,null,null,null,null,null,null,null,"ozvc.com",null,null,"uuc.com","lkbmz.com",null,null,null,null,null,null,null,"tjiqijw.com",null,null,"jvmovp.com",null,"lkbmz.com","tjiqijw.com",null,"rittbq.com",null,null,null,null,"vvv.com","acuqsax.com","vvv.com",null,"wmfbw.com",null,null,null,null,"sccat.com","vnzyagi.com",null,null,null,null,null,null,"zreiq.com",null,null,null,"vr.com",null,null,"cds.com","ulbj.com",null,null,null,null,null,null,null,"wtc.com","vnzyagi.com",null,"gfwgnez.com","sepa.com",null,"fazyh.com","fazyh.com",null,null,"ajzek.com",null,"sepa.com","sepa.com",null,"sepa.com","svatvoh.com",null,"sepa.com",null,null,null,"sbvcaq.com","sepa.com",null,null,"ebyw.com",null,null,null,null,null]
    # b=[null,null,null,null,null,null,null,null,"ozvc.com",null,null,"uuc.com","lkbmz.com",null,null,null,null,null,null,null,"tjiqijw.com",null,null,"jvmovp.com",null,"lkbmz.com","tjiqijw.com",null,"rittbq.com",null,null,null,null,"vvv.com","acuqsax.com","ojr.com",null,"wmfbw.com",null,null,null,null,"sccat.com","vnzyagi.com",null,null,null,null,null,null,"zreiq.com",null,null,null,"vr.com",null,null,"cds.com","ulbj.com",null,null,null,null,null,null,null,"wtc.com","vnzyagi.com",null,"gfwgnez.com","acuqsax.com",null,"fazyh.com","fazyh.com",null,null,"ajzek.com",null,"sepa.com","sepa.com",null,"sepa.com","svatvoh.com",null,"sepa.com",null,null,null,"sbvcaq.com","sepa.com",null,null,"ebyw.com",null,null,null,null,null]